#include "DDZSoundFun.h"
#include "SimpleAudioEngine.h"
#include "Game/Script/utility.h"
#include "Game/Script/SoundFun.h"
#include "DDZGameLogic.h"

namespace DDZSoundFun
{
	static const std::string LG_FLAG_PATH = "ddzsound/";
	static const std::string LG_FEMALE_PATH = "female/female_";
	static const std::string LG_MALE_PATH = "man/man_";

	static bool s_bMute = false;
	static float s_fSound1 = 0;
	static float s_fSound2 = 0;

	void playBackMusic(std::string kName)
	{
		SoundFun::Instance().playBackMusic(LG_FLAG_PATH + utility::a_u8(kName));
	}

	void stopBackMusic()
	{
		SoundFun::Instance().stopBackMusic();
	}

	void playEffectByGender(int iGender, std::string kName, std::string kKind /*= ".mp3"*/, bool bPreload /*= false*/)
	{
		std::string kNameUtf8 = utility::a_u8(LG_FLAG_PATH + (iGender ? LG_FEMALE_PATH : LG_MALE_PATH) + kName + kKind);

		SoundFun::Instance().playEffect(kNameUtf8, bPreload);
	}

	void playCardByGender(int iGender, int nCard)
	{
		int nValue = DDZGameLogic::Instance().GetCardValue(nCard);
		std::string kName = utility::toString(nValue);
		playEffectByGender(iGender, kName);
	}

	void playCardByGender_Pair(int iGender, int nCard)
	{
		int nValue = DDZGameLogic::Instance().GetCardValue(nCard);
		std::string kName = utility::toString("pair", nValue);
		playEffectByGender(iGender, kName);
	}

	void playCardByGender_Tuple(int iGender, int nCard)
	{
		int nValue = DDZGameLogic::Instance().GetCardValue(nCard);
		std::string kName = utility::toString("tuple", nValue);
		playEffectByGender(iGender, kName);
	}

	std::string getDefineSound(int iGender, std::string kStr)
	{
		return utility::toString(LG_FLAG_PATH, (iGender ? LG_FEMALE_PATH : LG_MALE_PATH), "fix_msg_", kStr, ".mp3");
	}

	void playCallStateByGender(int iGender, int nCallState, bool addRand)
	{
		std::string kName = EFFECT_CALL_STATE[nCallState - 1];
		if (addRand)
		{
			srand((DWORD)time(NULL));
			int nValue = rand() % 3;
			kName += utility::toString(nValue);
		}
		playEffectByGender(iGender, kName);
	}

	void playPassByGender(int iGender)
	{
		srand((DWORD)time(NULL));
		int nValue = rand() % 5;
		std::string kName = utility::toString("pass", nValue);

		playEffectByGender(iGender, kName);
	}
}
